home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC05Cust.Wind / RR.Wnd.asm2 < prev    next >
Encoding:
Text File  |  1990-05-17  |  41.6 KB  |  1,196 lines  |  [TEXT/pdos]

  1.                     EJECT
  2. *******************************************************************************
  3. *
  4. rrHit               start
  5. *
  6. * Description:      Test to see which part of the window was hit (if any).
  7. *
  8. *
  9. * Inputs:           param  = point to test
  10. *                        bits 0-15 = Y-coord;
  11. *                        bits 16-31 = X-coord.
  12. *                       (in local coordinates)
  13. *
  14. * Outputs:          result =  0 wNoHit       Not on the window at all
  15. *                            20 wInDrag      in Drag bar region
  16. *                           *21 wInGrow      in Grow region
  17. *                            22 wInGoAway    in Go-away region
  18. *                           *23 wInZoom      in Zoom region
  19. *                           *24 wInInfo      in Info bar
  20. *                            27 wInFrame     in the window, but none of above
  21. *                   carry  = clear
  22. *                   (Result numbers with an asterisk (*) next to them are
  23. *                    not supported in this window)
  24. *
  25. * External Refs:    NONE
  26. *
  27. * Entry Points:     NONE
  28. *
  29. *******************************************************************************
  30.                     using RRectDefProcData
  31.  
  32.                     lda <param          ; Make a copy of this so that it will
  33.                     sta myLocalPoint    ; be easier push its address onto the
  34.                     lda <param+2        ; stack.
  35.                     sta myLocalPoint+2
  36.  
  37.                     PushLong #myLocalPoint
  38.                     _LocalToGlobal
  39.  
  40. ; Check to see if the mouse was clicked in the strucRgn, which is also
  41. ; in global coordinates.
  42.  
  43.                     pha                 ; room for result
  44.                     PushLong #myLocalPoint ; push a pointer to the point
  45.                     ldy #owStrucRgn+2   ; push on strucRgn from theWindow
  46.                     lda [<theWindow],y
  47.                     pha
  48.                     dey
  49.                     dey
  50.                     lda [<theWindow],y
  51.                     pha
  52.                     _PtInRgn
  53.                     pla                 ; did we hit the strucRgn?
  54.                     beq done            ; no, return no hit
  55.  
  56.                     jsr ckGoAway        ; did we hit the goaway box?
  57.                     bne done            ; if so, it returns wInGoAway
  58.  
  59.                     ldy #owFrame        ; is the window draggable?
  60.                     lda [<theWindow],y
  61.                     and #fMove
  62.                     beq notDraggable    ; no, return wInFrame part
  63.  
  64.                     lda <param          ; load in the Y coordinate
  65.                     ldy #titleHeight
  66.                     cmp [<windGlobals],y ; is it in the title region
  67.                     bge notDraggable    ; no, so return wInFrame.
  68.  
  69.                     lda #wInDrag        ; return wInDrag
  70.                     bra done
  71.  
  72. notDraggable        ANOP
  73.                     lda #wInFrame       ; fall to exit routine
  74.  
  75. done                ANOP
  76.                     sta <result
  77.                     clc
  78.                     rts
  79.  
  80. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  81. ;
  82. ckGoAway            ANOP
  83. ;
  84. ; See if the mouse button was clicked while the cursor was in the
  85. ; goaway box. We simply use PtInRect for this.
  86. ;
  87. ; The window must both be active and have a close box in order for
  88. ; us to return a 'wInGoAway' condition.
  89. ;
  90.  
  91.                     ldy #owFrame        ; Check for these conditions in
  92.                     lda [<theWindow],y  ; one blow. If both bits are set,
  93.                     and #fHilited+fClose ; then check to see if we landed in
  94.                     cmp #fHilited+fClose ; the close box. If both are not
  95.                     bne notInGoAway     ; set, then leave.
  96.  
  97.                     ldy #closeHeight    ; calculate the dimensions of the
  98.                     lda [<windGlobals],y ; goAway box.
  99.                     clc
  100.                     adc goAwayRect
  101.                     sta goAwayRect+4
  102.                     ldy #closeWidth
  103.                     lda [<windGlobals],y
  104.                     clc
  105.                     adc goAwayRect+2
  106.                     sta goAwayRect+6
  107.  
  108.                     lda <param          ; we need this back in global
  109.                     sta myLocalPoint    ; coordinates
  110.                     lda <param+2
  111.                     sta myLocalPoint+2
  112.  
  113.                     pha                 ; room for result
  114.                     PushLong #myLocalPoint ; check the mouse click
  115.                     PushLong #goAwayRect
  116.                     _PtInRect
  117.                     pla
  118.                     beq notInGoAway     ; not there, return zero
  119.                     lda #wInGoAway      ; hit close box, return wInGoAway
  120.                     bra doneGoAway
  121.  
  122. notInGoAway         ANOP
  123.                     lda #wNoHit
  124. doneGoAway          ANOP
  125.                     rts
  126.  
  127. myLocalPoint        ds 4
  128. goAwayRect          dc i2'GAY,GAX,0,0'
  129.  
  130.                     end
  131.  
  132.                     EJECT
  133. *******************************************************************************
  134. *
  135. rrCalcRgns          start
  136. *
  137. * Description:      Calculate the content and structure regions of the window
  138. *                   in Global coordinates.
  139. *
  140. *
  141. * Inputs:           theWindow's portRect and boundsRect will be set
  142. *                   appropriately. NOTE: The strucRgn and contRgn must be
  143. *                   returned in GLOBAL coordinates. However, while the
  144. *                   settings of the portRect and boundsRect show the relative
  145. *                   positioning of the window on the desktop, they do not give
  146. *                   a rectangle in global coordinates on which we can base our
  147. *                   calculations. The routine "GetpRect" shows the correct way
  148. *                   to get a rectangle in global coordinates on which you
  149. *                   should base your calculations.
  150. *
  151. * Outputs:          result =  0
  152. *                   carry  = clear
  153. *                   theWindow.StrucRgn = frame region
  154. *                                       (region handle already allocated)
  155. *                   theWindow.ContRgn = content region
  156. *                                       (region handle already allocated)
  157. *
  158. * External Refs:    NONE
  159. *
  160. * Entry Points:     NONE
  161. *
  162. *******************************************************************************
  163.                     using RRectDefProcData
  164.  
  165.                     jsr GetpRect        ; get portRect; convert to Globals
  166. ;
  167. ; Create the rectangle we will use for creating the strucRgn. This is
  168. ; calculated based on the portRect, titleHeight, and screen mode.
  169. ;
  170.                     ldy #titleHeight    ; Get the suggested height of titlebar
  171.                     lda contRect        ; Raise the height of the strucRect by
  172.                     sec                 ;    that much.
  173.                     sbc [<windGlobals],y
  174.                     sta strucRect
  175.  
  176.                     lda contRect+4      ; lower bottom of the strucRect by 1
  177.                     ina
  178.                     sta strucRect+4
  179.  
  180.                     ldy #lineW          ; adjust width of the strucRect based
  181.                     lda contRect+2      ; on the size of the lineWidth
  182.                     sec
  183.                     sbc [<windGlobals],y ; one linewidth on the left...
  184.                     sta strucRect+2
  185.  
  186.                     lda contRect+6
  187.                     clc
  188.                     adc [<windGlobals],y ; ...and on the right.
  189.                     sta strucRect+6
  190.  
  191. ; now create the Content Region by doing a FrameRRect on the contRect, and
  192. ; adding a square region to it. First create a round rect region of the full
  193. ; content size.
  194.  
  195.                     _OpenRgn
  196.  
  197.                     PushLong #contRect
  198.                     ldy #xowRH          ; these are the radii of the corners
  199.                     PushWord [<theWindow],y
  200.                     ldy #xowRV
  201.                     PushWord [<theWindow],y
  202.                     _FrameRRect
  203.  
  204.                     ldy #owContRgn+2    ; push on the handle of the content
  205.                     lda [<theWindow],y  ; region stored in the window record
  206.                     sta ContRgnHandle+2
  207.                     pha
  208.                     dey
  209.                     dey
  210.                     lda [<theWindow],y
  211.                     sta ContRgnHandle
  212.                     pha
  213.                     _CloseRgn
  214.  
  215. ; Now create a square region to fill in the small upper corners.
  216.  
  217.                     pha
  218.                     pha
  219.                     _NewRgn
  220.                     PullLong TempRgn
  221.  
  222.                     lda contRect
  223.                     clc
  224.                     ldy #xowRV
  225.                     adc [<theWindow],y
  226.                     sta contRect+4
  227.  
  228.                     PushLong TempRgn
  229.                     PushLong #contRect
  230.                     _RectRgn
  231.  
  232. ; Add the two regions together.
  233.  
  234.                     PushLong ContRgnHandle
  235.                     PushLong TempRgn
  236.                     PushLong ContRgnHandle
  237.                     _UnionRgn
  238.  
  239.                     PushLong TempRgn
  240.                     _DisposeRgn
  241.  
  242. ; now create the Structure Region by doing a FrameRRect on the strucRect.
  243.  
  244.                     _OpenRgn
  245.  
  246.                     PushLong #strucRect
  247.                     ldy #xowRH          ; these are the radii of the corners
  248.                     PushWord [<theWindow],y
  249.                     ldy #xowRV
  250.                     PushWord [<theWindow],y
  251.                     _FrameRRect
  252.  
  253.                     ldy #owStrucRgn+2   ; push on the handle of the structure
  254.                     lda [<theWindow],y  ; region stored in the window record.
  255.                     sta StrucRgnHandle+2
  256.                     pha
  257.                     dey
  258.                     dey
  259.                     lda [<theWindow],y
  260.                     sta StrucRgnHandle
  261.                     pha
  262.                     _CloseRgn
  263.  
  264.                     clc
  265.                     rts
  266.  
  267. ContRgnHandle       ds 4
  268. StrucRgnHandle      ds 4
  269. TempRgn             ds 4
  270.  
  271. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  272. ;
  273. ; Fetches the portrect from the window record, and converts it to
  274. ; global coordinates. It leaves the rectangle in 'pRect' and 'contRect'
  275. ;
  276. ; LocalToGlobal conversion is done by subtracting boundsRect.y1 from the
  277. ; vertical coordinates of portRect, and doing similarly for the horizontal
  278. ; coordinates. This is essentially saying "How far away from the top and
  279. ; left edges of the screen is the portRect?".
  280. ;
  281.  
  282. GetpRect            ldy #oport+oboundsRect
  283.                     lda [<theWindow],y  ;Get the boundsRect y1,x1 and save it in a way
  284.                     sta atoglobal       ;that allows us to use it conveniently.
  285.                     sta atoglobal+4
  286.                     iny
  287.                     iny
  288.                     lda [<theWindow],y
  289.                     sta atoglobal+2
  290.                     sta atoglobal+6
  291.  
  292.                     ldy #oport+oportRect+6
  293.                     ldx #6              ;Globalize the portRect and save it where
  294. aa                  lda [<theWindow],y  ;"others" can get it.
  295.                     sec
  296.                     sbc atoglobal,x
  297.                     sta pRect,x
  298.                     sta contRect,x
  299.                     dey
  300.                     dey
  301.                     dex
  302.                     dex
  303.                     bpl aa
  304.  
  305.                     rts
  306.  
  307. atoglobal           ds 8
  308.  
  309.                     end
  310.  
  311.                     EJECT
  312. *******************************************************************************
  313. *
  314. rrNew               start
  315. *
  316. * Description:
  317. *
  318. * Perform any window record initialization. This routine is should set :
  319. *
  320. *   - the wRefCon, wContDraw, wColors, and wFrameCtls fields.
  321. *   - the fCtlTie, fVis, and fQContent bits in wFrame word.
  322. *   - any other fields in the Custom part of the record.
  323. *
  324. * The following has already been done:
  325. *
  326. *   - a window record has been allocated (as specified by the wNew call).
  327. *   - a port has been opened (as specified by the wPosition call).
  328. *   - handles have been placed in wStrucRgn, wContRgn, and wUpdateRgn.
  329. *   - wContDefProc points to us.
  330. *   - the window has been added to the window list, and wNext field set.
  331. *   - the fAllocated and fHilited bits have been set. All others are zero.
  332. *
  333. * Here is the window record. Asterisks are by the fields we have to set up:
  334. *
  335. *                     -4 owNext
  336. *                      0 owPort
  337. *                    170 owDefProc
  338. *                   *174 owrRefCon
  339. *                   *178 owContDraw
  340. *                    182 owReserved
  341. *                    186 owStrucRgn
  342. *                    190 owContRgn
  343. *                    194 owUpdateRgn
  344. *                    198 owCtls
  345. *                   *202 owFrameCtls
  346. *                   *206 owFrame
  347. *                   *208 owCustom
  348. *
  349. *
  350. * Inputs:           param  = pointer to parameter list supplied to _NewWindow
  351. *
  352. * Outputs:          result = zero
  353. *                   carry  = clear
  354. *
  355. * External Refs:    NONE
  356. *
  357. * Entry Points:     NONE
  358. *
  359. *******************************************************************************
  360.                     using RRectDefProcData
  361.  
  362. ;
  363. ; Set the frame bits based on the _NewWindow parmlist settings.
  364. ;
  365. ; We only really pay attention to: fClose, fMove.
  366. ;
  367. ; In addition, Window manager requires: fVis, fQContent, fCtlTie.
  368. ;
  369.  
  370.                     ldy #wFrameBits     ; Get the bits from the parm list.
  371.                     lda [<param],y      ; Make sure we don't affect fAllocated
  372.                     and #$FFFF-fAllocated-fHilited ; or fHilited.
  373.  
  374.                     ldy #owFrame        ; Get the bits as the WM has them.
  375.                     ora [<theWindow],y  ; Merge his and ours together...
  376.                     sta [<theWindow],y  ; ...and save them.
  377.  
  378. ; copy the wRefCon, wContDraw, and wColors from the parmlist
  379.  
  380.                     ldy #owrRefCon      ; dest index
  381.                     ldx #wRefCon        ; source index
  382.                     lda #8              ; bytes to move
  383.                     jsr CopyBlock
  384.  
  385. ; Copy all of the custom stuff into the end of the window record
  386.  
  387.                     ldy #windSize       ; used as dest index
  388.                     ldx #wCustom        ; used as source index
  389.                     lda #wEnd-wCustom   ; bytes to move
  390.                     jsr CopyBlock
  391.  
  392. ; The frame controls are already zeroed out by the Window manager before
  393. ; we get called, so we don't have to initialize that field.
  394.  
  395.  
  396. ; Finally, calculate the Frame and Content regions
  397.  
  398.                     jsr rrCalcRgns
  399.  
  400.                     clc
  401.                     rts
  402.  
  403.  
  404. CopyBlock           ANOP
  405.                     sta Count
  406. loop                ANOP
  407.                     phy                 ; save the dest index
  408.                     txy                 ; transfer in the source index
  409.                     lda [<param],y      ; get a source word
  410.                     ply                 ; retrieve the dest index
  411.                     sta [<theWindow],y  ; save the copy
  412.                     iny                 ; bump our indices
  413.                     iny
  414.                     inx
  415.                     inx
  416.                     dec Count           ; are we done?
  417.                     dec Count
  418.                     bne loop            ; no - copy some more
  419.  
  420.                     rts
  421.  
  422. Count               ds 2
  423.  
  424.                     end
  425.  
  426.                     EJECT
  427. *******************************************************************************
  428. *
  429. rrDispose           start
  430. *
  431. * Description:      Dispose of any additional fields created by the wNew call,
  432. *                   and tell the Window manager whether or not it should
  433. *                   continue the disposal. If we return FALSE, the Window
  434. *                   Manager will:
  435. *
  436. *                   - erase the window from the screen
  437. *                   - remove the window from the window list
  438. *                   - free any controls in wControls and wFrameCtls
  439. *                   - free the strucRgn, contRgn, and updateRgn handles
  440. *                   - close the GrafPort
  441. *                   - release the window record if it was allocated
  442. *                     dynamically (see allocate bit in wFrame field)
  443. *
  444. *
  445. * Inputs:           NONE
  446. *
  447. * Outputs:          to continue disposal: result = FALSE (zero)
  448. *                   to abort disposal:    result = TRUE  (non-zero)
  449. *                   in either case...     carry  = clear
  450. *
  451. * External Refs:    NONE
  452. *
  453. * Entry Points:     NONE
  454. *
  455. *******************************************************************************
  456.                     using RRectDefProcData
  457.  
  458.                     clc
  459.                     rts
  460.                     end
  461.  
  462.                     EJECT
  463. *******************************************************************************
  464. *
  465. rrGetDrag           start
  466. *
  467. * Description:      Return the address of the routine that will draw the
  468. *                   outline of the window as it is dragged. You can take the
  469. *                   easy way out and return $0000 0000 in 'result'; that will
  470. *                   tell the window manager take care of matters by dragging
  471. *                   the bounds rectangle of the strucRgn. I use my own routine
  472. *                   which draws a RoundRect.
  473. *
  474. *
  475. * Inputs:           NONE
  476. *
  477. * Outputs:          result = pointer to Drag routine, $0000 0000 for default
  478. *
  479. * External Refs:    NONE
  480. *
  481. * Entry Points:     NONE
  482. *
  483. *******************************************************************************
  484.                     using RRectDefProcData
  485.  
  486.                     lda #myDrag         ; return the pointer to my routine
  487.                     sta <result
  488.                     lda #^myDrag
  489.                     sta <result+2
  490.  
  491.                     jsr GetStrucRect    ; get a copy of the rect to drag
  492.  
  493.                     lda strucRect       ; make a local copy
  494.                     sta DragRect
  495.                     lda strucRect+2
  496.                     sta DragRect+2
  497.                     lda strucRect+4
  498.                     sta DragRect+4
  499.                     lda strucRect+6
  500.                     sta DragRect+6
  501.  
  502.                     ldy #xowRV          ; get the radii of the corners
  503.                     lda [<theWindow],y
  504.                     sta localRV
  505.  
  506.                     ldy #xowRH
  507.                     lda [<theWindow],y
  508.                     sta localRH
  509.  
  510.                     clc
  511.                     rts
  512.  
  513. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  514. ;
  515. ; This drag routine will be called with the following parameters:
  516. ;
  517. ;                   PUSH:WORD - delta X (signed)
  518. ;                   PUSH:WORD - delta Y (Your truly,)
  519. ;                   PUSH:BYTE[3] - return address
  520.  
  521. RTLAddr             equ 1
  522. DY                  equ RTLAddr+3
  523. DX                  equ DY+2
  524.  
  525. myDrag              ANOP
  526.                     clc                 ; offset/copy the original rectangle
  527.                     lda DragRect
  528.                     adc DY,s
  529.                     sta DragRect2
  530.  
  531.                     clc
  532.                     lda DragRect+2
  533.                     adc DX,s
  534.                     sta DragRect2+2
  535.  
  536.                     clc
  537.                     lda DragRect+4
  538.                     adc DY,s
  539.                     sta DragRect2+4
  540.  
  541.                     clc
  542.                     lda DragRect+6
  543.                     adc DX,s
  544.                     sta DragRect2+6
  545.  
  546.                     pha                 ; save the pen mode
  547.                     _GetPenMode
  548.  
  549.                     PushWord #modeXOR   ; and change it to XOR
  550.                     _SetPenMode
  551.  
  552.                     PushLong #DragRect2
  553.                     PushWord localRH
  554.                     PushWord localRV
  555.                     _FrameRRect
  556.  
  557.                     _SetPenMode         ; restore the old pen mode
  558.  
  559.                     lda RTLAddr,s       ; move the rtl address back up
  560.                     sta 5,s
  561.                     lda RTLAddr+1,s
  562.                     sta 6,s
  563.  
  564.                     pla                 ; remove the parameters
  565.                     pla
  566.  
  567.                     rtl                 ; back to dragrect!
  568.  
  569.  
  570. DragRect            ds 8
  571. DragRect2           ds 8
  572. localRH             ds 2
  573. localRV             ds 2
  574.  
  575.                     end
  576.  
  577.                     EJECT
  578. *******************************************************************************
  579. *
  580. rrGrowFrame         start
  581. *
  582. * Description:      Draw the outline of the window frame as it is grown. The
  583. *                   easiest way to deal with this routine is to ignore
  584. *                   everything passed to it, and return $0000 in result. This
  585. *                   will grow windows the normal way.
  586. *
  587. *
  588. * Inputs:           'param' points to the following data structure:
  589. *
  590. *        newsize    RECT  Rectangle that defines the new size
  591. *        drawFlag   WORD  TRUE to draw frame, false to erase
  592. *        startRect  RECT  Bounds of wStrucRgn when dragging started.
  593. *        deltaY     WORD  Vertical movement since starting to drag (signed).
  594. *        deltaX     WORD  Horizontal movement since starting to drag (signed).
  595. *
  596. * Outputs:          'result' should have the following bits set or clear:
  597. *
  598. *        0: TRUE if frame was drawn by us, FALSE if default frame is requested.
  599. *        1: TRUE if newSize RECT was changed in a custom fashion, FALSE if not.
  600. *
  601. * External Refs:    NONE
  602. *
  603. * Entry Points:     NONE
  604. *
  605. *******************************************************************************
  606.                     using RRectDefProcData
  607.  
  608. newSize             equ 0
  609. drawFlag            equ newSize+8
  610. startRect           equ drawFlag+2
  611. deltaY              equ startRect+8
  612. deltaX              equ deltaY+2
  613.  
  614. ;
  615. ; param is a pointer to a data block, the first 8 bytes of which
  616. ; is the rectangle we want to draw. So push Param on the stack for
  617. ; FrameRRect.
  618. ;
  619.                     PushLong <param
  620.                     ldy #xowRH
  621.                     PushWord [<theWindow],y
  622.                     ldy #xowRV
  623.                     PushWord [<theWindow],y
  624.                     _FrameRRect
  625.  
  626.                     lda #%0001          ; say the we drew the rect but
  627.                     sta <result         ; didn't change it.
  628.  
  629.                     clc
  630.                     rts
  631.                     end
  632.  
  633.                     EJECT
  634. *******************************************************************************
  635. *
  636. rrRecSize           start
  637. *
  638. * Description:      Return the size of the window record required by this
  639. *                   defProc. This number is the number of bytes needed beyond
  640. *                   the number normally allocated by the window manager.
  641. *
  642. *                   If you want to indicate that storage has already been
  643. *                   allocated (perhaps a a field was set in the NewWindow
  644. *                   parameter list, like wStorage in the standard window list),
  645. *                   then return the pointer to that record with bit 31 set.
  646. *
  647. *
  648. * Inputs:           param  = pointer to parameter list supplied to _NewWindow
  649. *
  650. * Outputs:          result = number of additional bytes required, or
  651. *                            pointer to window record with the high bit set
  652. *                   carry  = clear
  653. *
  654. * External Refs:    NONE
  655. *
  656. * Entry Points:     NONE
  657. *
  658. *******************************************************************************
  659.                     using RRectDefProcData
  660.  
  661. ; Let's see if there is storage defined in the parameter list
  662.  
  663.                     ldy #wStorage
  664.                     lda [<param],y
  665.                     iny
  666.                     iny
  667.                     ora [<param],y
  668.                     bne Allocated
  669.  
  670. ; No, so tell the window manager how large it should be
  671.  
  672.                     lda #xowEnd-windSize
  673.                     sta <result
  674.                     bra done
  675.  
  676. Allocated           ANOP
  677.                     lda [<param],y      ; Return the high word with the high
  678.                     ora #$8000          ; bit set to tell the WMgr what we did.
  679.                     sta <result+2
  680.                     dey
  681.                     dey
  682.                     lda [<param],y      ; Return the low word normally
  683.                     sta <result
  684.  
  685. done                ANOP
  686.                     clc
  687.                     rts
  688.                     end
  689.  
  690.                     EJECT
  691. *******************************************************************************
  692. *
  693. rrPosition          start
  694. *
  695. * Description:      Supply the rectangle to be used as the window's PortRect.
  696. *
  697. *
  698. * Inputs:           param  = pointer to parameter list supplied to _NewWindow
  699. *
  700. * Outputs:          result = pointer to the rect to be used as the PortRect
  701. *                   carry  = clear
  702. *
  703. * External Refs:
  704. *
  705. * Entry Points:
  706. *
  707. *******************************************************************************
  708.                     using RRectDefProcData
  709.  
  710. ; Take the pointer to the parameter list and add the offset to field
  711. ; that holds the portrect.
  712.  
  713.                     ADD4 #wPosition,<param,<result
  714.  
  715.                     clc
  716.                     rts
  717.                     end
  718.  
  719.                     EJECT
  720. *******************************************************************************
  721. *
  722. rrBehind            start
  723. *
  724. * Description:      This routine extracts the wPlane value of the parmList
  725. *                   passed to NewWindow and passes it back to the Window
  726. *                   Manager in 'result'. Pass back $FFFF FFFF to always place
  727. *                   the window on top, or $0000 0000 to place the window on the
  728. *                   bottom.
  729. *
  730. *
  731. * Inputs:           param  = pointer to parameter list passed to _NewWindow
  732. *
  733. * Outputs:          result = window pointer, $FFFF FFFF, or $0000 0000
  734. *                   carry  = clear
  735. *
  736. * External Refs:    NONE
  737. *
  738. * Entry Points:     NONE
  739. *
  740. *******************************************************************************
  741.                     using RRectDefProcData
  742.  
  743.                     ldy #wPlane         ; simply get what was specified in
  744.                     lda [<param],y      ; the parameter list supplied to
  745.                     sta <result         ; _NewWindow (since we are the only
  746.                     iny                 ; one who knows where is it) and return
  747.                     iny                 ; it to the Window Manager.
  748.                     lda [<param],y
  749.                     sta <result+2
  750.  
  751.                     clc
  752.                     rts
  753.                     end
  754.  
  755.                     EJECT
  756. *******************************************************************************
  757. *
  758. rrCallDefProc       start
  759. *
  760. * Description:      Generic call to the defProc. Through this, the Window
  761. *                   Manager can access the fields in the custom window's
  762. *                   data in response to the many Get/Set calls.
  763. *
  764. *
  765. * Inputs:           On entry, 'param' points to the following block of data:
  766. *
  767. *                   WORD : dRequest     Requested operation number
  768. *                   WORD : paramID      Parameter block type:
  769. *                                         $0000-7FFF reserved by system
  770. *                                         $8000-FFFF reserved for application
  771. *                                         (We only handle type $0000 System
  772. *                                          in this sample)
  773. *                   XXXX : newParam     Operation specific data
  774. *
  775. * Outputs:          Call specific. See technote for more details.
  776. *
  777. * External Refs:
  778. *                   Import rrSetTitle
  779. *                   Import rrSetColor
  780. *                   Import rrSetFrame
  781. *                   Import rrGetTitle
  782. *                   Import rrGetColor
  783. *                   Import rrGetFrame
  784. *                   Import handleWTask
  785. *
  786. * Entry Points:     NONE
  787. *
  788. *******************************************************************************
  789.                     using RRectDefProcData
  790.  
  791. dRequest            equ 0
  792. paramID             equ dRequest+2
  793. newParam            equ paramID+2
  794.  
  795. MaxDRequest         equ 33
  796.  
  797.                     ldy #paramID        ; Do we know this paramID type?
  798.                     lda [<param],y
  799.                     bne ignore          ; $0000, ignore all others
  800.  
  801.                     lda [<param]        ; dRequest
  802.                     cmp #MaxDRequest+1  ; is this request in range?
  803.                     bcs ignore          ; no so leave
  804.                     asl a               ; yes, turn into index into proc table
  805.                     tax
  806.                     jmp (dRequestTable,x)
  807.  
  808. dRequestTable       ANOP
  809.                     dc i2'ignore'       ;  0 wSetOrgmask
  810.                     dc i2'ignore'       ;  1 wSetMaxGrow
  811.                     dc i2'ignore'       ;  2 wSetScroll
  812.                     dc i2'ignore'       ;  3 wSetPage
  813.                     dc i2'ignore'       ;  4 wSetInfoRefCon
  814.                     dc i2'ignore'       ;  5 wSetInfoDraw
  815.                     dc i2'ignore'       ;  6 wSetOrigin
  816.                     dc i2'ignore'       ;  7 wSetDataSize
  817.                     dc i2'ignore'       ;  8 wSetZoomRect
  818.                     dc i2'rrSetTitle'   ;  9 wSetTitle
  819.                     dc i2'rrSetColor'   ; 10 wSetColorTable
  820.                     dc i2'rrSetFrame'   ; 11 wSetFrameFlag
  821.                     dc i2'ignore'       ; 12 wGetOrgMask
  822.                     dc i2'ignore'       ; 13 wGetMaxGrow
  823.                     dc i2'ignore'       ; 14 wGetScroll
  824.                     dc i2'ignore'       ; 15 wGetPage
  825.                     dc i2'ignore'       ; 16 wGetInfoRefCon
  826.                     dc i2'ignore'       ; 17 wGetInfoDraw
  827.                     dc i2'ignore'       ; 18 wGetOrigin
  828.                     dc i2'ignore'       ; 19 wGetDataSize
  829.                     dc i2'ignore'       ; 20 wGetZoomRect
  830.                     dc i2'rrGetTitle'   ; 21 wGetTitle
  831.                     dc i2'rrGetColor'   ; 22 wGetColorTable
  832.                     dc i2'rrGetFrame'   ; 23 wGetFrameFlag
  833.                     dc i2'ignore'       ; 24 wGetInfoRect
  834.                     dc i2'ignore'       ; 25 wGetDrawInfo
  835.                     dc i2'ignore'       ; 26 wGetStartInfoDraw
  836.                     dc i2'ignore'       ; 27 wGetEndInfoDraw
  837.                     dc i2'ignore'       ; 28 wZoomWindow
  838.                     dc i2'ignore'       ; 29 wStartDrawing
  839.                     dc i2'rrStartMove'  ; 30 wStartMove (defined in this PROC)
  840.                     dc i2'ignore'       ; 31 wStartGrow
  841.                     dc i2'rrNewSize'    ; 32 wNewSize (defined in this PROC)
  842.                     dc i2'handleWTask'  ; 33 wTask
  843.  
  844. rrStartMove         ldy #newParam+2     ; Preparing to move the window. Examine
  845.                     lda [<param],y      ; the proposed destination rectangle
  846.                     sta <result+2       ; and see if it is OK. If it is, simply
  847.                     dey                 ; return it. If it isn't, then change
  848.                     dey                 ; it. We will like it, so we'll just
  849.                     lda [<param],y      ; return what we get.
  850.                     sta <result
  851.                     clc
  852.                     rts
  853.  
  854. rrNewSize           ANOP
  855.                     lda #1              ; Always return TRUE. This tells the
  856.                     sta <result         ; window manager to redraw only
  857.                     clc                 ; uncovered contents.
  858.                     rts
  859.  
  860. ignore              clc
  861.                     rts
  862.  
  863.                     end
  864.  
  865.                     EJECT
  866. *******************************************************************************
  867. *
  868. handleWTask         start
  869. *
  870. * Description:      Called to handle FindWindow results passed on by
  871. *                   TaskMaster. Since TaskMaster only handles event that occur
  872. *                   in menus and system windows, custom window defprocs must
  873. *                   handle all of the rest. These include:
  874. *
  875. *                   wInContent          wInDrag
  876. *                   wInGrow             wInGoAway
  877. *                   wInZoom             wInInfo
  878. *                   wInFrame
  879. *
  880. *
  881. * Inputs:           'param' points to the following block of data:
  882. *
  883. *                   WORD:dRequest       = 33 for wTask
  884. *                   WORD:paramID        we only handle type $0000 System calls
  885. *                   LONG:newParam       Pointer to Task Record
  886. *                   WORD:newParam       result from FindWindow
  887. *
  888. * Outputs:          'result' equals the following:
  889. *
  890. *                                       Low Word            High Word
  891. *                                       -----------------   -------------------
  892. *    If the event was handled:          Zero                Action taken
  893. *    If the event was not handled:      FindWindow result   ignored
  894. *
  895. * External Refs:    NONE
  896. *
  897. * Entry Points:     NONE
  898. *
  899. *******************************************************************************
  900.                     using RRectDefProcData
  901.  
  902. dRequest            equ 0
  903. paramID             equ dRequest+2
  904. newParam            equ paramID+2
  905. TaskRecPtr          equ newParam
  906. FWResult            equ TaskRecPtr+4
  907.  
  908. TaskRec             equ work
  909.  
  910.                     ldy #TaskRecPtr+2   ; get the pointer to the Event Record
  911.                     lda [<param],y      ; into 'TaskRec', aka 'work'.
  912.                     sta <TaskRec+2
  913.                     dey
  914.                     dey
  915.                     lda [<param],y
  916.                     sta <TaskRec
  917.  
  918.                     ldy #FWResult       ; get the Findwindow result
  919.                     lda [<param],y
  920.  
  921.                     sec                 ; turn it into an index
  922.                     sbc #wInContent
  923.                     bcc callIgnore      ; out of range, so ignore
  924.                     cmp #wInFrame-wInContent+1
  925.                     bcc doit
  926. callIgnore          lda #wInSpecial-wInContent+1
  927. doit                asl a
  928.                     tax
  929.                     jmp (wTaskTable,x)
  930.  
  931. wTaskTable          dc i2'doInContent'  ; doInContent
  932.                     dc i2'doInDrag'     ; doInDrag
  933.                     dc i2'ignoreTask'   ; doInGrow
  934.                     dc i2'doInGoAway'   ; doInGoAway
  935.                     dc i2'ignoreTask'   ; doInZoom
  936.                     dc i2'ignoreTask'   ; doInInfo
  937.                     dc i2'ignoreTask'   ; doInSpecial (default ignore)
  938.                     dc i2'ignoreTask'   ; doInDeskItem (not used)
  939.                     dc i2'doInContent'  ; doInFrame
  940.  
  941. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  942. ;
  943. ; TaskMaster needs us to handle a wInContent event. Check the TaskMask
  944. ; field to see if the application wants us to handle it. If so, bring the
  945. ; window to front. Then check to see if the application wants to know what
  946. ; we just did. If so, return wInContent. If not, return null.
  947.  
  948. doInContent         ANOP
  949.                     ldy #owmTaskMask    ; do we handle clicks in the content?
  950.                     lda [<TaskRec],y
  951.                     and #tmContent
  952.                     bne Bogus0010       ; yes - just select the window
  953.                     brl ignoreTask      ; no - so pretend we weren't here.
  954.  
  955. Bogus0010           jsr mySelectWindow
  956.  
  957.                     ldy #owFrame        ; do we tell the app what we did?
  958.                     lda [<theWindow],y
  959.                     and #fQContent
  960.                     beq Passively       ; no - just return a nullEvt
  961.  
  962.                     ldx #0
  963.                     lda #wInContent     ; pass this on to the application
  964.                     brl Exit
  965. Passively           ANOP
  966.                     ldx #wInContent     ; This is what we did.
  967.                     lda #0              ; Signal that event was handled
  968.                     brl Exit
  969.  
  970. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  971. ;
  972. ; TaskMaster needs us to handle a wInDrag event. Check the TaskMask
  973. ; field to see if the application wants us to handle it. If so, call
  974. ; DragWindow with the same parameters described in the TaskMaster
  975. ; psuedo-code in the ToolBox Reference. Then check to see if the Apple
  976. ; key was down. If it wasn't, bring the window forward. Finally, return
  977. ; null.
  978. ;
  979. doInDrag            ANOP
  980.                     ldy #owmTaskMask    ; do we do drags?
  981.                     lda [<TaskRec],y
  982.                     and #tmDragW
  983.                     bne Bogus0020       ; yes - get on with it.
  984.                     brl ignoreTask      ; no - so pretend we weren't here.
  985. Bogus0020           ANOP
  986.                     PushWord #0         ; drag resolution
  987.                     ldy #owhere+2       ; global coord of cursor
  988.                     PushWord [<TaskRec],y ; first X
  989.                     dey
  990.                     dey
  991.                     PushWord [<TaskRec],y ; then Y
  992.                     PushWord #8         ; grace buffer around bounds
  993.                     PushLong #0         ; default cursor boundary
  994.                     ldy #owmTaskData+2  ; push on window's grafport
  995.                     PushWord [<TaskRec],y
  996.                     dey
  997.                     dey
  998.                     PushWord [<TaskRec],y
  999.                     _DragWindow         ; Call DrawWindow ourselves
  1000.  
  1001.                     ldy #omodifiers     ; if the Apple Key is down then
  1002.                     lda [<TaskRec],y    ; don't bring the window to front
  1003.                     and #appleKey
  1004.                     bne doneDrag
  1005.  
  1006.                     jsr mySelectWindow
  1007. doneDrag            ANOP
  1008.                     ldx #wInDrag        ; This is what we did.
  1009.                     lda #0              ; Signal that event was handled
  1010.                     bra Exit            ; Exit the DefProc
  1011.  
  1012. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1013. ;
  1014. ; TaskMaster needs us to handle a wInGoAway event. Check the TaskMask
  1015. ; field to see if the application wants us to handle it. If so, call
  1016. ; TrackGoAway. If it returns TRUE, then return wInGoAway to the
  1017. ; application. If it returns FALSE, return wNoHit.
  1018. ;
  1019. doInGoAway          ANOP
  1020.                     pha                 ; space for boolean result
  1021.                     ldy #owhere+2       ; global coord of cursor
  1022.                     PushWord [<TaskRec],y ; first X
  1023.                     dey
  1024.                     dey
  1025.                     PushWord [<TaskRec],y ; then Y
  1026.                     ldy #owmTaskData+2  ; push on window's grafport
  1027.                     PushWord [<TaskRec],y
  1028.                     dey
  1029.                     dey
  1030.                     PushWord [<TaskRec],y
  1031.                     _TrackGoAway
  1032.                     pla
  1033.                     beq noClose
  1034.  
  1035.                     ldx #0              ; Close selected. Tell app that we
  1036.                     lda #wInGoAway      ; clicked in the goAway box.
  1037.                     bra Exit
  1038. noClose             ANOP
  1039.                     ldx #wInGoAway      ; Close not selected. Tell the app that
  1040.                     lda #wNoHit         ; we tracked it, but that everything is
  1041.                     bra Exit            ; OK now.
  1042.  
  1043.  
  1044. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1045. ;
  1046. ; Local routine to bring the window forward if we need to.
  1047. ;
  1048. mySelectWindow      ANOP
  1049.                     lda <theWindow      ; get the pointer to the window so that
  1050.                     clc                 ; we can  bring it to front.
  1051.                     adc #4
  1052.                     tax
  1053.                     lda <theWindow+2
  1054.                     pha
  1055.                     phx
  1056.                     _SelectWindow
  1057.                     rts
  1058.  
  1059.  
  1060. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1061. ;
  1062. ; For some reason, we need to ignore a task. Either we were asked to handle
  1063. ; an event we know nothing about, or the TaskMask prohibited us from 
  1064. ; handling a certain event. This routine simply echos the result found by
  1065. ; FindWindow back to the application.
  1066.  
  1067. ignoreTask          ldy #FWResult       ; ignore by echoing the FindWindow
  1068.                     lda [<param],y      ;   result.
  1069.                     ldx #0              ; fall through to Exit.
  1070.  
  1071. Exit                ANOP
  1072.                     sta <result         ; TaskMaster result on the stack
  1073.                     stx <result+2       ; Low word of TaskData
  1074.  
  1075.                     clc
  1076.                     rts
  1077.                     end
  1078.  
  1079.                     EJECT
  1080. *******************************************************************************
  1081. *
  1082. HouseKeeping        start
  1083. *
  1084. * Description:      Housekeeping calls. Set and get various fields. These will
  1085. *                   redraw the window if necessary.
  1086. *
  1087. *
  1088. * Inputs:
  1089. *
  1090. * Outputs:
  1091. *
  1092. * External Refs:
  1093. *                   Import drawFrame
  1094. *
  1095. * Entry Points:
  1096. *                   entry rrSetTitle
  1097. *                   entry rrSetColor
  1098. *                   entry rrSetFrame
  1099. *                   entry rrGetTitle
  1100. *                   entry rrGetColor
  1101. *                   entry rrGetFrame
  1102. *
  1103. *******************************************************************************
  1104.                     using RRectDefProcData
  1105.  
  1106. dRequest            equ 0
  1107. paramID             equ dRequest+2
  1108. newParam            equ paramID+2
  1109.  
  1110.  
  1111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1112.  
  1113. rrSetTitle          entry
  1114.                     ldy #xowTitle+2
  1115.                     bra SetLong
  1116.  
  1117. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1118.  
  1119. rrSetColor          entry
  1120.                     ldy #xowColorPtr+2
  1121.                     bra SetLong
  1122.  
  1123. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1124.  
  1125. rrSetFrame          entry
  1126.                     ldy #owFrame
  1127.                     bra SetWord
  1128.  
  1129. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1130.  
  1131. rrGetTitle          entry
  1132.                     ldy #xowTitle+2
  1133.                     bra GetLong
  1134.  
  1135. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1136.  
  1137. rrGetColor          entry
  1138.                     ldy #xowColorPtr+2
  1139.                     bra GetLong
  1140.  
  1141. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1142.  
  1143. rrGetFrame          entry
  1144.                     ldy #xowColorPtr
  1145.                     bra GetWord
  1146.  
  1147. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1148.  
  1149. SetLong             ANOP
  1150.                     phy
  1151.                     ldy #newParam+2
  1152.                     lda [<param],y
  1153.                     ply
  1154.                     sta [<theWindow],y
  1155.                     dey
  1156.                     dey
  1157. SetWord             phy
  1158.                     lda #newParam
  1159.                     lda [<param],y
  1160.                     ply
  1161.                     sta [<theWindow],y
  1162.  
  1163.                     lda <theWindow      ; Now redraw the window frame
  1164.                     clc
  1165.                     adc #4
  1166.                     tax
  1167.                     lda <theWindow+2
  1168.                     pha
  1169.                     phx
  1170.                     _StartFrameDrawing  ; must be called by defproc
  1171.  
  1172.                     jsr drawFrame
  1173.  
  1174.                     _EndFrameDrawing    ; reverses StartFrameDrawing call
  1175.  
  1176.                     clc
  1177.                     rts
  1178.  
  1179. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1180. ;
  1181. ; Called by the rrGetxxxxx routines above. Enter with Y holding the
  1182. ; offset to a LONG parameter in the window record. This routine will
  1183. ; fetch that value and put it into 'result'.
  1184. ;
  1185.  
  1186. GetLong             ANOP
  1187.                     lda [<theWindow],y
  1188.                     sta <result+2
  1189.                     dey
  1190.                     dey
  1191. GetWord             lda [<theWindow],y
  1192.                     sta <result
  1193.                     clc
  1194.                     rts
  1195.                     end
  1196.